package com.shlh.saas.controller;

import com.shlh.saas.common.Result;
import com.shlh.saas.service.UserBalanceService;
import com.shlh.saas.service.impl.UserBalanceServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员控制器
 */
@RestController
@RequestMapping("/saas/admin")
public class AdminController {
    
    private static final Logger log = LoggerFactory.getLogger(AdminController.class);
    
    @Autowired
    private UserBalanceService userBalanceService;
    
    /**
     * 手动触发同步用户余额记录
     * 确保所有用户在user_balances表中都有相应的记录
     * 
     * @return 同步结果
     */
    @PostMapping("/sync-user-balances")
    public Result<String> syncUserBalances() {
        log.info("收到手动触发同步用户余额记录的请求");
        
        try {
            // 手动调用同步方法
            userBalanceService.syncUserBalances();
            
            return Result.success("用户余额记录同步成功");
        } catch (Exception e) {
            log.error("同步用户余额记录失败: {}", e.getMessage(), e);
            return Result.error("同步用户余额记录失败: " + e.getMessage());
        }
    }
} 